<%--
  Created by IntelliJ IDEA.
  User: cos
  Date: 2022/3/9
  Time: 11:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<button id="btn1">点击</button>
<button id="btn2">点击2</button>
<button id="btn3">点击3</button>


<script>
    $(function () {
        $("#btn1").click(function () {
            $.get("${pageContext.request.contextPath}/ajax/d1", function (data) {
                alert(data);
            });
        })


        $("#btn2").click(function () {
            $.ajax({
                type: "get",
                url: "${pageContext.request.contextPath}/ajax/getUserOne",
                success: function (data) {
                    // alert(data);
                    //后台给是字符串
                    var user = JSON.parse(data);
                    alert(user.id + "-" + user.name + "-" + user.sex + "-" + user.age);
                }
            })
        })
        $("#btn3").click(function () {
            $.ajax({
                type: "get",
                url: "${pageContext.request.contextPath}/ajax/getUserTwo",
                success: function (data) {
                    // alert(data);
                    // var user = JSON.parse(data);
                    //js 对象 json转换过来的对象
                    // json对象
                    //服务器返回的是json对象
                    alert(typeof data);
                    alert(data.id + "-" + data.name + "-" + data.sex + "-" + data.age);
                }
            })
        })
    })
</script>
</body>
</html>
